//
// Created by alexa on 5/13/2024.
//

#ifndef ARTILLERYSYSTEM_UNITSSERVICE_H
#define ARTILLERYSYSTEM_UNITSSERVICE_H


#include "../../repositories/unit-repository/UnitRepository.h"
#include "../../entities/combat-unit/launcher/Launcher.h"
#include "../../entities/combat-unit/self-propelled-launcher/SelfPropelledLauncher.h"
#include "../crews-service/CrewsService.h"
#include "../../exceptions/EntityNotFound.h"
#include "../missiles-service/MissilesService.h"
#include <unordered_map>
class BattalionsService;

class UnitsService {
private:
    UnitRepository repository;
    CrewsService *crewsService;
    MissilesService *missilesService;
    BattalionsService *battalionsService;
public:
    void setBattalionsService(BattalionsService *battalionsService);

    explicit UnitsService(CrewsService *crewsService, MissilesService *missilesService);

    CombatUnit *getById(string id);

    vector<CombatUnit *> getAll();

    Launcher *createLauncher(string name, int railsCount, float shotsDelay);

    CombatUnit *findByCrewId(string crewId);

    void saveUnit(CombatUnit *unit);

    SelfPropelledLauncher *
    createSelfPropelledLauncher(
            const string &name,
            int railsCount,
            float shotsDelay,
            float length,
            float width,
            float maxSpeed,
            float weight,
            float powerReserve,
            float preparingTime
    );

    void deleteOne(string id);

    void setCrew(string unitId, string crewId);

    void setMissile(string unitId, string missileId);

    vector<CombatUnit *> getManyByIds(vector<string> ids);

    static bool isPropelledType(CombatUnit *unit);

    vector<Specialization> getMissingSpecializations(string unitId);

    CombatUnit *findByMissileId(string missileId);

    float moveCombatUnit(string unitId, float newX, float newY);

    void setAimForCombatUnit(string unitId, float aimX, float aimY);

    void refuelUnit(CombatUnit *unit);

    void reloadUnit(string unitId);

    unordered_map<string, float> unitShoot(CombatUnit *unit);

    friend class MainService;
};

#include "../battalions-service/BattalionsService.h"

#endif //ARTILLERYSYSTEM_UNITSSERVICE_H
